// Copyright (c) 2025 Shenzhen Kaihong Digital Industry Development Co., Ltd.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use maestro_derive::MsgTag;
use ohmw_derive::Encode;

#[derive(Encode, MsgTag)]
#[msg_tag(case = "snake_case")]
pub struct EchoRet {
    pub id: u32,
}

pub fn echo(id: u32) -> EchoRet {
    EchoRet { id: id + 1 }
}

#[cfg(test)]
mod test {
    use maestro_message::serialize_msg;

    use crate::protocol::EchoRet;

    #[test]
    fn test_serialize_msg() {
        let msg = EchoRet { id: 1 };
        let buf = serialize_msg(msg).unwrap();
        assert_eq!(buf, vec![16, 0, 0, 0, 8, 0, 0, 0, 101, 99, 104, 111, 95, 114, 101, 116, 1, 0, 0, 0]);
    }
}